﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Scripting;


namespace UserScripts
{
    class CustomAttributes : ScriptBase
    {        
        static void Main()
        {
        }
        static DataTable GetAttributeTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("attributeValue", typeof(int)); // Add column for attribute
            table.Columns.Add("stepNumber", typeof(int)); // Add column for Step Number
            table.Columns.Add("defense", typeof(int)); // Add column for Defense Ratings
            table.Columns.Add("carryingCapacity", typeof(int)); // Add column for Carrying Capacity
            table.Columns.Add("deathRating", typeof(int)); // Add column for Death Rating
            table.Columns.Add("uncRating", typeof(int)); // Add column for Unconsiousness Rating
            table.Columns.Add("woundThreshold", typeof(int)); // Add column for Wound Threshold
            table.Columns.Add("recTests", typeof(int)); // Add column for Recovery Tests per Day
            table.Columns.Add("mysticArmor", typeof(int)); // Add column for Mystic Armor
            DataColumn[] primaryKey = new DataColumn[1];
            primaryKey[0] = table.Columns["attributeValue"];
            table.PrimaryKey = primaryKey;  // Set the attribute value to the primary key

            // Populate the table with data
            table.Rows.Add(1, 2, 2, 5, 16, 10, 3, 1, 0);
            table.Rows.Add(2, 2, 3, 10, 20, 11, 4, 1, 0);
            table.Rows.Add(3, 2, 3, 15, 22, 13, 4, 1, 0);
            table.Rows.Add(4, 3, 4, 20, 23, 14, 5, 1, 0);
            table.Rows.Add(5, 3, 4, 25, 24, 15, 5, 1, 0);
            table.Rows.Add(6, 3, 4, 30, 26, 17, 6, 1, 0);
            table.Rows.Add(7, 4, 5, 40, 27, 18, 6, 1, 0);
            table.Rows.Add(8, 4, 5, 50, 28, 19, 7, 2, 0);
            table.Rows.Add(9, 4, 6, 60, 30, 21, 7, 2, 0);
            table.Rows.Add(10, 5, 6, 70, 31, 22, 8, 2, 0);
            table.Rows.Add(11, 5, 7, 80, 32, 24, 8, 2, 1);
            table.Rows.Add(12, 5, 7, 95, 34, 26, 9, 2, 1);
            table.Rows.Add(13, 6, 7, 110, 35, 27, 9, 2, 1);
            table.Rows.Add(14, 6, 8, 125, 36, 28, 10, 3, 2);
            table.Rows.Add(15, 6, 8, 140, 38, 30, 10, 3, 2);
            table.Rows.Add(16, 7, 9, 160, 39, 31, 11, 3, 2);
            table.Rows.Add(17, 7, 9, 180, 40, 32, 11, 3, 3);
            table.Rows.Add(18, 7, 10, 200, 42, 34, 12, 3, 3);
            table.Rows.Add(19, 8, 10, 230, 43, 35, 12, 3, 3);
            table.Rows.Add(20, 8, 10, 260, 44, 36, 13, 4, 4);
            table.Rows.Add(21, 8, 11, 290, 46, 39, 13, 4, 4);
            table.Rows.Add(22, 9, 11, 330, 47, 40, 13, 4, 4);
            table.Rows.Add(23, 9, 12, 370, 48, 41, 14, 4, 5);
            table.Rows.Add(24, 9, 12, 410, 50, 43, 14, 4, 5);
            table.Rows.Add(25, 10, 13, 460, 51, 44, 15, 4, 5);
            table.Rows.Add(26, 10, 13, 510, 52, 45, 15, 5, 6);
            table.Rows.Add(27, 10, 13, 560, 54, 47, 15, 5, 6);
            table.Rows.Add(28, 11, 14, 620, 55, 48, 16, 5, 6);
            table.Rows.Add(29, 11, 14, 680, 56, 49, 16, 5, 7);
            table.Rows.Add(30, 11, 15, 740, 58, 51, 17, 5, 7);
            return table;
        }
        static DataTable GetDefDiscTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("level", typeof(int)); // Add column for level
            table.Columns.Add("case1", typeof(int)); // Modification Pattern 1
            table.Columns.Add("case2", typeof(int)); // Modification Pattern 2
            table.Columns.Add("case3", typeof(int)); // Modification Pattern 3
            table.Columns.Add("case4", typeof(int)); // Modification Pattern 4
            table.Columns.Add("case5", typeof(int)); // Modification Pattern 5
            table.Columns.Add("case6", typeof(int)); // Modification Pattern 6
            table.Columns.Add("case7", typeof(int)); // Modification Pattern 7
            table.Columns.Add("case8", typeof(int)); // Default
            DataColumn[] primaryKey = new DataColumn[1];
            primaryKey[0] = table.Columns["level"];
            table.PrimaryKey = primaryKey; // Set the level to the primary key

            // Populate the table with data
            table.Rows.Add(1, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(2, 1, 1, 0, 0, 0, 0, 1, 0);
            table.Rows.Add(3, 1, 1, 0, 0, 0, 0, 1, 0);
            table.Rows.Add(4, 1, 1, 0, 0, 0, 0, 1, 0);
            table.Rows.Add(5, 1, 1, 0, 0, 0, 0, 1, 0);
            table.Rows.Add(6, 1, 1, 0, 0, 0, 0, 1, 0);
            table.Rows.Add(7, 1, 1, 0, 0, 0, 0, 1, 0);
            table.Rows.Add(8, 2, 2, 0, 0, 0, 0, 2, 0);
            table.Rows.Add(9, 2, 2, 0, 0, 0, 0, 2, 0);
            table.Rows.Add(10, 3, 3, 0, 0, 0, 0, 3, 0);
            table.Rows.Add(11, 4, 3, 1, 1, 1, 0, 3, 0);
            table.Rows.Add(12, 5, 4, 1, 1, 1, 0, 4, 0);
            table.Rows.Add(13, 5, 4, 1, 2, 2, 1, 4, 0);
            table.Rows.Add(14, 6, 5, 1, 3, 2, 1, 4, 0);
            table.Rows.Add(15, 6, 5, 2, 4, 3, 2, 4, 0);
            return table;
        }
        static DataTable GetRecTestDiscTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("level", typeof(int)); // Add column for level
            table.Columns.Add("case1", typeof(int)); // Modification Pattern 1
            table.Columns.Add("case2", typeof(int)); // Modification Pattern 2
            table.Columns.Add("case3", typeof(int)); // Modification Pattern 3
            table.Columns.Add("case4", typeof(int)); // Modification Pattern 4
            table.Columns.Add("case5", typeof(int)); // Modification Pattern 5
            table.Columns.Add("case6", typeof(int)); // Modification Pattern 6
            table.Columns.Add("case7", typeof(int)); // Modification Pattern 7
            table.Columns.Add("case8", typeof(int)); // Modification Pattern 8
            table.Columns.Add("case9", typeof(int)); // Default
            DataColumn[] primaryKey = new DataColumn[1];
            primaryKey[0] = table.Columns["level"];
            table.PrimaryKey = primaryKey; // Set the level to the primary key

            // Populate the table with data 
            table.Rows.Add(1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(2, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(3, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(4, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(5, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(6, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(7, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(8, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(9, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(10, 0, 0, 1, 0, 1, 0, 0, 0, 0);
            table.Rows.Add(11, 1, 1, 1, 0, 1, 0, 0, 0, 0);
            table.Rows.Add(12, 1, 1, 1, 1, 1, 1, 0, 1, 0);
            table.Rows.Add(13, 1, 1, 1, 1, 1, 1, 0, 1, 0);
            table.Rows.Add(14, 2, 1, 2, 2, 1, 1, 2, 3, 0);
            table.Rows.Add(15, 2, 2, 2, 2, 1, 2, 2, 3, 0);
            return table;
        }
        static DataTable GetInitDiscTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("level", typeof(int)); // Add column for level
            table.Columns.Add("case1", typeof(int)); // Modification Pattern 1
            table.Columns.Add("case2", typeof(int)); // Modification Pattern 2
            table.Columns.Add("case3", typeof(int)); // Modification Pattern 3
            table.Columns.Add("case4", typeof(int)); // Modification Pattern 4
            table.Columns.Add("case5", typeof(int)); // Modification Pattern 5
            table.Columns.Add("case6", typeof(int)); // Modification Pattern 6
            table.Columns.Add("case7", typeof(int)); // Modification Pattern 7
            table.Columns.Add("case8", typeof(int)); // Modification Pattern 8
            table.Columns.Add("case9", typeof(int)); // Modification Pattern 9
            table.Columns.Add("case10", typeof(int)); // Default
            DataColumn[] primaryKey = new DataColumn[1];
            primaryKey[0] = table.Columns["level"];
            table.PrimaryKey = primaryKey; // Set the level to the primary key

            // Populate the table with data 
            table.Rows.Add(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            table.Rows.Add(10, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0);
            table.Rows.Add(11, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0);
            table.Rows.Add(12, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0);
            table.Rows.Add(13, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0);
            table.Rows.Add(14, 1, 2, 1, 1, 0, 3, 1, 1, 2, 0);
            table.Rows.Add(15, 2, 2, 1, 1, 2, 3, 2, 1, 2, 0);
            return table;
        }
        static int GetModifiedAttribute(Actor actor, string attribute)
        {
            GlobalInteraction useglobal = new GlobalInteraction();
            int attrib = actor.GetAttribute(attribute);
            string bonus;
            string penalty;
            switch (attribute)
            {
                case "Strength":
                    bonus = "StrBonus";
                    penalty = "StrPenalty";
                    break;
                case "Dexterity":
                    bonus = "DexBonus";
                    penalty = "DexPenalty";
                    break;
                case "Toughness":
                    bonus = "TouBonus";
                    penalty = "TouPenalty";
                    break;
                case "Perception":
                    bonus = "PerBonus";
                    penalty = "PerPenalty";
                    break;
                case "Willpower":
                    bonus = "WilBonus";
                    penalty = "WilPenalty";
                    break;
                case "Charisma":
                    bonus = "ChaBonus";
                    penalty = "ChaPenalty";
                    break;
                default:
                    bonus = "foo";
                    penalty = "bar";
                    break;
            }
            int attribBonus = useglobal.GetSingleIntGlobal(actor, bonus);
            int attribPenalty = useglobal.GetSingleIntGlobal(actor, penalty);
            attrib = attrib + attribBonus - attribPenalty;
            if (attrib <= 0)
            {
                attrib = 1;
            }
            return attrib;
        }
        static int GetPhysDef(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Dexterity");
            int physDef;
            if (attribute <= 30)
            {
                string rowInfo;
                int physDefBase;
                int physDefMod;
                DataTable baseTable = GetAttributeTable();
                DataTable modTable = GetDefDiscTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                physDefBase = Convert.ToInt32(baseRow["defense"]); // Retrieve the defense rating that corresponds to the attribute

                // Determine the Physical Defense modifier based on the Class and Level of the actor
                if (actor.Class == "Air Sailor")
                {
                    rowInfo = "case1";
                }
                else if (actor.Class == "Archer" || actor.Class == "Beastmaster" || actor.Class == "Scout" || actor.Class == "Sky Raider" || actor.Class == "Thief" || actor.Class == "Warrior")
                {
                    rowInfo = "case2";
                }
                else if (actor.Class == "Elementalist" || actor.Class == "Illusionist" || actor.Class == "Nethermancer" || actor.Class == "Weaponsmith" || actor.Class == "Wizard" || actor.Class == "Troubador")
                {
                    rowInfo = "case3";
                }
                else if (actor.Class == "Swordmaster")
                {
                    rowInfo = "case4";
                }
                else
                {
                    rowInfo = "case8";
                }
                DataRow modRow = modTable.Rows[actor.Level - 1]; // Index starts at 0
                physDefMod = Convert.ToInt32(modRow[rowInfo]); // Retrieve the modifier for the given level and class
                physDef = physDefBase + physDefMod;
            }
            else
            {
                physDef = Convert.ToInt32(0.4287 * attribute + 1.8552);
            }
            return physDef;
        }
        static int GetSpellDef(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Perception");
            int spellDef;
            if (attribute <= 30)
            {
                string rowInfo;
                int spellDefBase;
                int spellDefMod;
                DataTable baseTable = GetAttributeTable();
                DataTable modTable = GetDefDiscTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                spellDefBase = Convert.ToInt32(baseRow["defense"]); // Retrieve the defense rating that corresponds to the attribute


                // Determine the Spell Defense modifier based on the Class and Level of the actor
                if (actor.Class == "Air Sailor" || actor.Class == "Beastmaster" || actor.Class == "Sky Raider" || actor.Class == "Swordmaster")
                {
                    rowInfo = "case3";
                }
                else if (actor.Class == "Archer" || actor.Class == "Scout" || actor.Class == "Thief" || actor.Class == "Troubador" || actor.Class == "Warrior")
                {
                    rowInfo = "case5";
                }
                else if (actor.Class == "Elementalist" || actor.Class == "Illusionist" || actor.Class == "Nethermancer" || actor.Class == "Weaponsmith" || actor.Class == "Wizard")
                {
                    rowInfo = "case2";
                }
                else
                {
                    rowInfo = "case8";
                }
                DataRow modRow = modTable.Rows[actor.Level - 1]; // Index starts at 0
                spellDefMod = Convert.ToInt32(modRow[rowInfo]); // Retrieve the modifier for the given level and class
                spellDef = spellDefBase + spellDefMod;
            }
            else
            {
                spellDef = Convert.ToInt32(0.4287 * attribute + 1.8552);
            }
            return spellDef;
        }
        static int GetSocialDef(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Charisma");
            int socialDef;
            if (attribute <= 30)
            {
                string rowInfo;
                int socialDefBase;
                int socialDefMod;
                DataTable baseTable = GetAttributeTable();
                DataTable modTable = GetDefDiscTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                socialDefBase = Convert.ToInt32(baseRow["defense"]); // Retrieve the defense rating that corresponds to the attribute


                // Determine the Social Defense modifier based on the Class and Level of the actor
                if (actor.Class == "Air Sailor")
                {
                    rowInfo = "case6";
                }
                else if (actor.Class == "Archer" || actor.Class == "Scout" || actor.Class == "Thief" || actor.Class == "Warrior")
                {
                    rowInfo = "case3";
                }
                else if (actor.Class == "Beastmaster" || actor.Class == "Elementalist" || actor.Class == "Illusionist" || actor.Class == "Nethermancer" || actor.Class == "Sky Raider" || actor.Class == "Weaponsmith" || actor.Class == "Wizard")
                {
                    rowInfo = "case5";
                }
                else if (actor.Class == "Swordmaster")
                {
                    rowInfo = "case7";
                }
                else if (actor.Class == "Troubador")
                {
                    rowInfo = "case2";
                }
                else
                {
                    rowInfo = "case8";
                }
                DataRow modRow = modTable.Rows[actor.Level - 1]; // Index starts at 0
                socialDefMod = Convert.ToInt32(modRow[rowInfo]); // Retrieve the modifier for the given level and class
                socialDef = socialDefBase + socialDefMod;
            }
            else
            {
                socialDef = Convert.ToInt32(0.4287 * attribute + 1.8552);
            }
            return socialDef;
        }
        static int GetCarryingCapacity(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Strength");
            int carryingCapacity;
            if (attribute <= 30)
            {
                DataTable baseTable = GetAttributeTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                carryingCapacity = Convert.ToInt32(baseRow["carryingCapacity"]); // Retrieve the value that corresponds to the attribute
            }
            else
            {
                carryingCapacity = Convert.ToInt32(0.0279 * Math.Pow(attribute, 3) - 0.228 * Math.Pow(attribute, 2) + 6.682 * attribute - 3.6043);
            }
            return carryingCapacity;
        }
        static int GetDeathRating(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Toughness");
            int deathRating;
            if (attribute <= 30)
            {
                int deathRatingMod;
                int deathRatingBase;
                int durMod;
                DataTable baseTable = GetAttributeTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                deathRatingBase = Convert.ToInt32(baseRow["deathRating"]); // Retrieve the value that corresponds to the attribute
                int durRank = actor.GetAbilityLevel("Durability");
                if (actor.Class == "Air Sailor" || actor.Class == "Archer" || actor.Class == "Scout" || actor.Class == "Thief" || actor.Class == "Weaponsmith")
                {
                    durMod = 6;
                }
                else if (actor.Class == "Beastmaster" || actor.Class == "Swordmaster")
                {
                    durMod = 7;
                }
                else if (actor.Class == "Elementalist" || actor.Class == "Illusionist" || actor.Class == "Nethermancer" || actor.Class == "Wizard")
                {
                    durMod = 4;
                }
                else if (actor.Class == "Sky Raider")
                {
                    durMod = 8;
                }
                else if (actor.Class == "Warrior")
                {
                    durMod = 9;
                }
                else
                {
                    durMod = 0;
                }
                deathRatingMod = durRank * durMod;
                deathRating = deathRatingBase + deathRatingMod;
            }
            else
            {
                deathRating = Convert.ToInt32(1.3348 * attribute + 17.644);
            }
            return deathRating;
        }
        static int GetUncRating(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Toughness");
            int uncRating;
            if (attribute <= 30)
            {
                int uncRatingBase;
                int uncRatingMod;
                DataTable baseTable = GetAttributeTable();
                DataRow baseRow = baseTable.Rows[actor.GetAttribute("Toughness") - 1]; // Index starts at 0
                uncRatingBase = Convert.ToInt32(baseRow["uncRating"]); // Retrieve the value that corresponds to the attribute
                int durRank = actor.GetAbilityLevel("Durability");
                int durMod;
                if (actor.Class == "Air Sailor" || actor.Class == "Archer" || actor.Class == "Scout" || actor.Class == "Thief" || actor.Class == "Weaponsmith")
                {
                    durMod = 5;
                }
                else if (actor.Class == "Beastmaster" || actor.Class == "Swordmaster" || actor.Class == "Sky Raider")
                {
                    durMod = 6;
                }
                else if (actor.Class == "Elementalist" || actor.Class == "Illusionist" || actor.Class == "Nethermancer" || actor.Class == "Wizard")
                {
                    durMod = 3;
                }
                else if (actor.Class == "Warrior")
                {
                    durMod = 7;
                }
                else
                {
                    durMod = 0;
                }
                uncRatingMod = durRank * durMod;
                uncRating = uncRatingBase + uncRatingMod;
            }
            else
            {
                uncRating = Convert.ToInt32(1.4328 * attribute + 8.2644);
            }
            return uncRating;
        }
        static int GetWoundThreshold(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Toughness");
            int woundThreshold;
            if (attribute <= 30)
            {
                DataTable baseTable = GetAttributeTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                woundThreshold = Convert.ToInt32(baseRow["woundThreshold"]); // Retrieve the value that corresponds to the attribute
            }
            else
            {
                woundThreshold = Convert.ToInt32(-0.0028 * Math.Pow(attribute, 2) + 0.5552 * attribute + 2.5557);
            }
            if (actor.Race == "Obsidimen") woundThreshold += 3;
            return woundThreshold;
        }
        static int GetRecTests(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Toughness");
            int recTests;
            if (attribute <= 30)
            {
                string rowInfo;
                int recTestsBase;
                int recTestsMod;
                DataTable baseTable = GetAttributeTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                recTestsBase = Convert.ToInt32(baseRow["recTests"]); // Retrieve the value that corresponds to the attribute
                DataTable modTable = GetRecTestDiscTable();
                // Determine the Recovery Tests modifier based on the Class and Level of the actor
                if (actor.Class == "Air Sailor")
                {
                    rowInfo = "case1";
                }
                else if (actor.Class == "Archer")
                {
                    rowInfo = "case2";
                }
                else if (actor.Class == "Beastmaster" || actor.Class == "Scout")
                {
                    rowInfo = "case3";
                }
                else if (actor.Class == "Elementalist")
                {
                    rowInfo = "case7";
                }
                else if (actor.Class == "Illusionist")
                {
                    rowInfo = "case8";
                }
                else if (actor.Class == "Nethermancer" || actor.Class == "Troubador")
                {
                    rowInfo = "case4";
                }
                else if (actor.Class == "Swordmaster")
                {
                    rowInfo = "case5";
                }
                else if (actor.Class == "Thief" || actor.Class == "Weaponsmith" || actor.Class == "Wizard")
                {
                    rowInfo = "case6";
                }
                else
                {
                    rowInfo = "case9";
                }
                DataRow modRow = modTable.Rows[actor.Level - 1]; // Index starts at 0
                recTestsMod = Convert.ToInt32(modRow[rowInfo]); // Retrieve the modifier for the given level and class
                recTests = recTestsBase + recTestsMod;
            }
            else
            {
                recTests = Convert.ToInt32(0.1655 * attribute + 0.3378);
            }
            return recTests;
        }
        static int GetMysticArmor(Actor actor)
        {
            int attribute = GetModifiedAttribute(actor, "Willpower");
            int mysticArmor;
            if (attribute <= 30)
            {
                DataTable baseTable = GetAttributeTable();
                DataRow baseRow = baseTable.Rows[attribute - 1]; // Index starts at 0
                mysticArmor = Convert.ToInt32(baseRow["mysticArmor"]); // Retrieve the value that corresponds to the attribute
            }
            else
            {
                mysticArmor = Convert.ToInt32(-0.0002 * Math.Pow(attribute, 3) + 0.231 * Math.Pow(attribute, 2) - 0.2012 * attribute + 0.3386);
            }
            return mysticArmor;
        }
        public int GetStepNumber(int attrib)
        {
            int stepnumber;
            if (attrib <= 30)
            {
                DataTable baseTable = GetAttributeTable();
                DataRow baseRow = baseTable.Rows[attrib - 1]; // Index starts at 0
                stepnumber = Convert.ToInt32(baseRow["stepNumber"]); // Retrieve the step that corresponds to the attribute
            }
            else
            {
                stepnumber = Convert.ToInt32(0.3304 * attrib + 1.3793);
            }
            return stepnumber;
        }
        public int GetInitStep(Actor actor)
        {
            CustomAttributes ca = new CustomAttributes();
            int attribute = ca.GetCustomAttributes(actor, "Dexterity");
            int initStep;             
            int initStepBase;
            PacketReader reader1 = new PacketReader(actor.Globals["InitPenalty"]);
            int initPenalty = reader1.ReadInt32();
            PacketReader reader2 = new PacketReader(actor.Globals["InitBonus"]);
            int initBonus = reader2.ReadInt32();
            int initDiscMod;
            string rowInfo;
            initStepBase = ca.GetStepNumber(attribute);
            if (actor.Class == "Air Sailor" || actor.Class == "Elementalist" || actor.Class == "Scout" || actor.Class == "Swordmaster")
            {
                rowInfo = "case1";
            }
            else if (actor.Class == "Archer" || actor.Class == "Sky Raider")
            {
                rowInfo = "case2";
            }
            else if (actor.Class == "Beastmaster")
            {
                rowInfo = "case3";
            }
            else if (actor.Class == "Illusionist" || actor.Class == "Weaponsmith")
            {
                rowInfo = "case4";
            }
            else if (actor.Class == "Nethermancer")
            {
                rowInfo = "case5";
            }
            else if (actor.Class == "Thief")
            {
                rowInfo = "case6";
            }
            else if (actor.Class == "Troubador")
            {
                rowInfo = "case7";
            }
            else if (actor.Class == "Warrior")
            {
                rowInfo = "case8";
            }
            else if (actor.Class == "Wizard")
            {
                rowInfo = "case9";
            }
            else
            {
                rowInfo = "case10";
            }
            DataTable modTable = GetInitDiscTable();
            DataRow modRow = modTable.Rows[actor.Level - 1]; // Index starts at 0
            initDiscMod = Convert.ToInt32(modRow[rowInfo]); // Retrieve the modifier for the given level and class
            initStep = initStepBase + initDiscMod +initBonus + initPenalty;
            return initStep;
        }
        public int GetCustomAttributes(Actor actor, string attribute)
        {
            if (attribute == "PhysicalDefense")
            {
                return GetPhysDef(actor);
            }
            else if (attribute == "SpellDefense")
            {
                return GetSpellDef(actor);
            }
            else if (attribute == "SocialDefense")
            {
                return GetSocialDef(actor);
            }
            else if (attribute == "CarryingCapacity")
            {
                return GetCarryingCapacity(actor);
            }
            else if (attribute == "DeathRating")
            {
                return GetDeathRating(actor);
            }
            else if (attribute == "UnconsciousnessRating")
            {
                return GetUncRating(actor);
            }
            else if (attribute == "WoundThreshold")
            {
                return GetWoundThreshold(actor);
            }
            else if (attribute == "RecoveryTestsPerDay")
            {
                return GetRecTests(actor);
            }
            else if (attribute == "MysticArmor")
            {
                return GetMysticArmor(actor);
            }
            else if (attribute == "ModStrength")
            {
                return GetModifiedAttribute(actor, "Strength");
            }
            else if (attribute == "ModDexterity")
            {
                return GetModifiedAttribute(actor, "Dexterity");
            }
            else if (attribute == "ModToughness")
            {
                return GetModifiedAttribute(actor, "Toughness");
            }
            else if (attribute == "ModPerception")
            {
                return GetModifiedAttribute(actor, "Percpetion");
            }
            else if (attribute == "ModWillpower")
            {
                return GetModifiedAttribute(actor, "Willpower");
            }
            else if (attribute == "ModCharisma")
            {
                return GetModifiedAttribute(actor, "Charisma");
            }
            else if (attribute == "Initiative")
            {
                return GetInitStep(actor);
            }
            else
            {
                return 0;
            }
        }
    }
}
